<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <el-card style="height: 750px; overflow-y: auto">
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo" style="overflow-y: auto">
              <userInfo :user="user" v-if="user && user.userName" :assesses="assesses" :tasks="tasks" :trainings="trainings" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd :user="user"/>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import {getUserProfile, unBindOpenid} from "@/api/system/user";

export default {
  name: "Profile",
  components: {userAvatar, userInfo, resetPwd},
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
      bindBtnLoading: false,
      assesses: [],
      tasks:[],
      trainings:[],
    };
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        if(response.data.ancestorNames){
          if(response.data.ancestorNames !=='昌泰集团'){
            response.data.ancestorNames = response.data.ancestorNames.substring(5,response.data.ancestorNames.length)
          }
        }
        this.user = response.data;
        this.assesses = response.assesses;
        this.tasks = response.tasks;
        this.trainings = response.trainings;

        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    },
    chatUnBandHandler(userId) {
      this.$confirm('确认解绑微信?', '提示', {type: 'warning'}).then(() => {
        this.bindBtnLoading = true
        unBindOpenid(userId).then(() => {
          this.getUser();
          this.$modal.msgSuccess("解绑成功");
        }).finally(() => {
          this.bindBtnLoading = false
        })
      })
    }
  }
};
</script>
